#include <dirent.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>

int flag = 0;

unsigned long get_inode(char *name) {
	struct stat e;
	if (lstat(name,&e) == -1) {
		printf("lstat error\n");
		return 0;
	}
	return e.st_ino;
}

void pwd(unsigned long inode) {
	struct dirent *dp;
	struct stat e;
	DIR* dir;

	if(get_inode("..") == inode)
		return;

	chdir("..");
	if((dir = opendir(".")) == NULL) {
		printf("opendir error\n");
		return;
	}	
	while ( (dp = readdir(dir)) != NULL) {
		if (lstat(dp->d_name,&e) == -1) {
			printf("lstat error\n");
			break;	
		}
		if (e.st_ino == inode) {
			flag = 1;
			pwd(get_inode("."));
			printf("/%s",dp->d_name);
			break;
		}
	}
	closedir(dir);
}

int main(int args , char * argv[]) {
	pwd(get_inode("."));
	if(!flag) printf("/");	
	printf("\n");
	return 0;
}


